package com.egg.auth.model;

import com.egg.common.core.constant.StringPool;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 登录用户信息
 */

@Data
@ApiModel(value = "登录用户信息")
public class LoginUserInfo implements Serializable {


    @Data
    @ApiModel(value = "登录用户部门信息")
    public static class Dept implements Serializable {


        @ApiModelProperty(value = "部门ID")
        private Long id;

        @ApiModelProperty(value = "部门名称")
        private String name;

        @ApiModelProperty(value = "部门是否启用")
        private Boolean enabled;


    }

    @Data
    @ApiModel(value = "登录用户角色信息")
    public static class Role implements Serializable {


        @ApiModelProperty(value = "角色ID")
        private Long id;

        @ApiModelProperty(value = "角色编码")
        private String authCode;

        @ApiModelProperty(value = "角色名称")
        private String name;

        @ApiModelProperty(value = "启用状态")
        private Boolean enabled;

        @ApiModelProperty(value = "数据范围")
        private String dataScope;

    }

    @ApiModelProperty(value = "设备端类型")
    private String deviceType;

    @ApiModelProperty(value = "租户ID")
    private String tenantId;

    @ApiModelProperty(value = "用户ID")
    private Long userId;

    @ApiModelProperty(value = "用户昵称")
    private String nickname;

    @ApiModelProperty(value = "用户头像")
    private String avatar;

    @ApiModelProperty(value = "部门信息")
    private List<Dept> deptList;

    @ApiModelProperty(value = "角色信息")
    private List<Role> roleList;

    @ApiModelProperty(value = "功能权限", notes = "关联的所有接口")
    private List<String> funcPerms;

    @ApiModelProperty(value = "数据权限", notes = "关联的所有部门")
    private List<Long> dataPerms;

    @ApiModelProperty(value = "登录类型")
    private String accountType;

    @ApiModelProperty(value = "登录IP地址")
    private String ip;

    @ApiModelProperty(value = "登录标识")
    private String loginId;

    /**
     * 获取登录id
     */
    public String getLoginId() {
        if (null == accountType) {
            throw new IllegalArgumentException("用户类型不能为空");
        }
        if (null == tenantId) {
            throw new IllegalArgumentException("用户ID不能为空");
        }
        if (null == userId) {
            throw new IllegalArgumentException("用户ID不能为空");
        }
        return deviceType + StringPool.COLON + tenantId + StringPool.COLON + userId;
    }

}
